﻿using System;
using System.Collections.Generic;
using System.Linq;
using Generator.Selections;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagrams;

namespace Manor.CslaDesigner
{
    public partial class ClassShape
    {
        public override void OnDoubleClick(DiagramPointEventArgs e)
        {
            var mc = ModelElement as ModelClass;
            //if (mc == null) return;
            
            //var c = new StartGeneratorSelection(mc.Name);
            //c.Execute();

            //if (c.SelectedTable!= null)
            //{               
            //    using (var transaction = mc.Store.TransactionManager.BeginTransaction("update model"))
            //    {
            //        mc.Name = c.SelectedTable.TableName;

            //        foreach (var column in c.SelectedTable.ColumnList)
            //        {
            //            var ma = new ModelAttribute(mc.Partition, null)
            //                {
            //                    Name = column.ColumnName,
            //                    Type = column.DataType.ToString(),
            //                    Required = column.Mandatory,                                
            //                }
            //            ;

            //            if (column.MaxLen.HasValue)
            //                ma.MaximalLength = column.MaxLen.Value;

            //            mc.Attributes.Add(ma);                        
            //        }
            //        transaction.Commit();
            //    }
            //}
            base.OnDoubleClick(e);
            e.Handled = true;
        }

    }
}